<?php
namespace app\admin\controller;
/**
* 商户配置
*/
class Shcon extends Common
{
	// 配置列表
	public function member_list(){
		$sel = db('conf')->select();
		$this->assign('mchid',$sel);
		return view();

	}


	// 添加页面
	public function member_add(){

		$merchant=db('rwm')->field("id,salesname")->select();
		$this->assign('merchant',$merchant);
		if(!empty($_POST)){
			if($_POST['type'] == 1){
				$user = db('conf')->where("mid = ".$_POST['user']."")->find();
	          if(!empty($user)){
	             echo json_encode($user);
	             exit ;
	          }else{
	          	echo 1;
	          	exit ;
	          }

			}else if($_POST['type'] == 2){
                $user = db('zfb')->where('zfb_mid = '.$_POST['user'].'')->find();
                if(!empty($user)){
                  echo json_encode($user);
                  exit ;
                }else{
                	echo 1;
                	exit ;
                }
			}
          
           
		}else{
			return view();
		}
	}
	// 添加
	public function medber_add_ad(){


		if($_POST['typesy'] == 1){ //配置微信
		//	$data = input('post.');
           $data = array(
			'appid' => input('post.appid'),
			'appSecret' => input('post.appSecret'),
			'mchId' => input('post.mchId'),
			'key' => input('post.key'),
			'body' => input('post.body'),
			'zf_title' => input('post.zf_title'),
			'beizhu' => input('post.beizhu'),
			'mid' => input('post.mid'),
		  );
            $add = db('conf');
            $sel = $add->where("mid = ".$_POST['mid']."")->field("id,mchId,mid")->find();
            if(!empty($sel)){
            	$mid = $add->where("mid = ".$_POST['mid']."")->update($data);
               if($mid == 1){
            		  echo 0;
           			   exit ;
        	  }else{
          			  echo 1;
          			  exit ;
        	  }
            }else{
            	$ad = $add->insert($data);
            	 if($ad == 1){
		 		 	echo 2;
		 		 	exit ;
			  }else{
         		   echo 3;
         		   exit ;
			  }
			  exit ;
            }
		}else if($_POST['typesy'] == 2){
			$adq = db('zfb');
			$dats = array(
              'zfb_appid' => input('post.appid'),
              'zfb_public' => input('post.zfb_public'),
              'zfb_private' => input('post.zfb_sy'),
              'zfb_mchId' => input('post.zfb_mchId'),
              'zfb_key' => input('post.zfb_key'),
              'zfb_body' => input('post.zfb_body'),
              'zfb_title' => input('post.zfb_title'),
              'zfb_bz' => input('post.zfb_bz'),
              'zfb_mid' => input('post.zfb_mid')
				);
			$sel = $adq->where("zfb_mid = ".$_POST['zfb_mid']."")->find();
			if(!empty($sel)){
	
              $mid = $adq->where("zfb_mid = ".$_POST['zfb_mid']."")->update($dats);
                if($mid == 1){
           		   echo 0;
           		   exit ;
        	 	 }else{
          			  echo 1;
          			  exit ;
         	 	}
			}else{
				$ad = $adq->insert($dats);
				if($ad == 1){
					  	echo 2;
					  	exit ;
				  }else{
        			    echo 3;
        			    exit ;
				  }
			}
			
			//---------- 
		}

	}

	
}
